
package com.shop.cloud.mall.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.cloud.common.core.util.R;
import com.shop.cloud.common.log.annotation.SysLog;
import com.shop.cloud.mall.admin.service.VipRightsService;
import com.shop.cloud.mall.common.entity.VipRights;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 会员权益
 *
 * @author
 * @date 2024-03-19 15:18:40
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/viprights")
@Tag(description = "viprights", name = "会员权益管理")
public class VipRightsController {

    private final VipRightsService vipRightsService;

    /**
     * 会员权益分页列表
     * @param page 分页对象
     * @param vipRights 会员权益
     * @return
     */
    @Operation(summary = "会员权益分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ato.hasAuthority('mall:viprights:index')")
    public R getPage(Page page, VipRights vipRights) {
        return R.ok(vipRightsService.page(page, Wrappers.query(vipRights)));
    }

    /**
     * 会员权益查询
     * @param id
     * @return R
     */
    @Operation(summary = "会员权益查询")
    @GetMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:viprights:get')")
    public R getById(@PathVariable("id") String id) {
        return R.ok(vipRightsService.getById(id));
    }

    /**
     * 会员权益新增
     * @param vipRights 会员权益
     * @return R
     */
    @Operation(summary = "会员权益新增")
    @SysLog("新增会员权益")
    @PostMapping
    @PreAuthorize("@ato.hasAuthority('mall:viprights:add')")
    public R save(@RequestBody VipRights vipRights) {
        return R.ok(vipRightsService.save(vipRights));
    }

    /**
     * 会员权益修改
     * @param vipRights 会员权益
     * @return R
     */
    @Operation(summary = "会员权益修改")
    @SysLog("修改会员权益")
    @PutMapping
    @PreAuthorize("@ato.hasAuthority('mall:viprights:edit')")
    public R updateById(@RequestBody VipRights vipRights) {
        return R.ok(vipRightsService.updateById(vipRights));
    }

    /**
     * 会员权益删除
     * @param id
     * @return R
     */
    @Operation(summary = "会员权益删除")
    @SysLog("删除会员权益")
    @DeleteMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:viprights:del')")
    public R removeById(@PathVariable String id) {
        return R.ok(vipRightsService.removeById(id));
    }

}
